<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<body class="easyui-layout">
<!-- 说明 字符串：project，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
    <!-- 主表  -->
    <table id="project_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
           data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/project-list/1/20',
					  method:'get',
					  toolbar:'#tb',
					  loadMsg : '数据加载中',
					  showFooter: true" >
        <#include "/common/thead.html">
    </table>
</div>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
    <div>
        项目名称:<input class="easyui-textbox" style="width:120px" id="pro_name_like">
        项目公司:<input class="easyui-textbox" style="width:120px" id="pro_company_like">
        项目状态:
        <input class="easyui-combobox" name="pro_state"id="pro_state"
               data-options="
				url : '/constants/proj_state',
				method: 'get',
				valueField:'key',
				textField:'value',
				">
        项目分类：
        <input class="easyui-combobox" name="pro_category"id="pro_category"
               data-options="
				url : '#',
				method: 'get',
				valueField:'value',
				textField:'text',
				">
        <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
    </div>
    <div style="margin:5px 0;"></div>
    <#include "/common/button.html">
</div>

<#--<#include "/common/dlg.html">-->
<script type="text/javascript">
    function proStateFormatter(val){
        if(val == 1){
            return "入库";
        }else if(val == 2){
            return "立项";
        }else {
            return "决策";
        }
    }


    <!-- 按钮操作 -->

    var url;

    //新增
    // $("#add").click(function () {
    // 	$('#dlg').dialog('open').dialog('center').dialog('setTitle','新增项目');
    // 	$('#fm').form('clear');
    // 	url = '/project-ins-upd-del/-1';
    // })
    $('#add').click(function () {
        var url = '/project-add?id=-1';
        var index = layer.open({
            title:'项目修改',
            type: 2,
            area: ['700px', '450px'],
            fixed: false, //不固定
            maxmin: false,
            content: url
        });
    });

    //编辑
    $("#edit").click(function () {
        var row = $('#project_table').datagrid('getSelected');
        if (row){
            var url = '/project-add?id='+row.id;
            var index = layer.open({
                title:'用户修改',
                type: 2,
                area: ['700px', '450px'],
                fixed: false, //不固定
                maxmin: false,
                content: url
            });
        } else {
            layer.msg("请选择需要编辑的项目",{icon: 2})
        }
        $('#project_table').datagrid('reload');
    })
    //行复制
    $("#copy").click(function () {
        var row = $('#project_table').datagrid('getSelected');
        if (row){
            url = '/project-add?id='+row.id+"&sql=copy";
            var index = layer.open({
                title:'用户修改',
                type: 2,
                area: ['700px', '450px'],
                fixed: false, //不固定
                maxmin: false,
                content: url
            });
        } else {
            layer.msg("请选择需要复制的行的项目",{icon: 2})
        }
        $('#project_table').datagrid('reload');
    })

    function save(){
        $('#fm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                $('#project_table').datagrid('reload');    // reload the user data
            }
        });
    }

    //删除
    $("#delete").click(function () {
        var row = $('#project_table').datagrid('getSelected');
        if(!row){
            layer.msg("请选择需要删除的项目",{icon: 2})
        }else{
            url = '/project-ins-upd-del/'+row.id;
            $.messager.confirm('删除信息','确定删除此项目?',function(r){
                if (r){
                    $.post(url,{deleteFlag:'Y',tm:new Date()},function(result){
                        $('#project_table').datagrid('reload');    // reload the user data
                    });
                }
            });
        }
    })
    $('#export').click(function(){
        window.location = "/project-download";
    });

    //审核
    $("#check").click(function () {
        var row = $('#project_table').datagrid('getSelected');
        if(!row){
            layer.msg("请选择需要审核的项目",{icon: 2})
        }else{
            url = '/proState-check/'+row.id;
            $.messager.confirm('审核信息','确定更改此项目状态?',function(r){
                if (r){
                    $.post(url,function(result){
                        $('#project_table').datagrid('reload');    // reload the user data
                        alert(result.msg);
                    });
                }
            });
        }
    })
    $('#export').click(function(){
        window.location = "/project-download";
    });
</script>




<!--条件查询-->
<script>
    $("#searchByParameter").click(function(){
        var pro_name_like = $("#pro_name_like").val();
        var pro_company_like = $("#pro_company_like").val();
        var pro_category = $("#pro_category").val();
        var pro_state = $("#pro_state").val();
        var handler = '/project-list/1/20?pro_name_like='+pro_name_like+"&pro_company_like="+pro_company_like+"&pro_state="+pro_state+"&pro_category="+pro_category;
        $('#project_table').datagrid('options').url = handler;
        $('#project_table').datagrid('reload');
    });
</script>

<!-- 分页 -->
<script type="text/javascript">
    $(function(){
        var p = $('#project_table').datagrid().datagrid('getPager');
        p.pagination({
            pageSize: 20, //每页显示的记录条数，默认为10
            pageList: [20, 40, 60], //可以设置每页记录条数的列表
            onSelectPage: function (pageNumber, pageSize) {
                if(pageNumber==0){
                    pageNumber = 1;
                }
                var pro_name_like = $("#pro_name_like").val();
                var pro_company_like = $("#pro_company_like").val();
                var pro_category = $("#pro_category").val();
                var pro_state = $("#pro_state").val();
                var handler = '/project-list/'+pageNumber+'/'+pageSize+'?pro_name_like='+pro_name_like+"&pro_company_like="+pro_company_like+"&pro_state="+pro_state+"&pro_category="+pro_category;
                $('#project_table').datagrid('options').url = handler;
                $('#project_table').datagrid('reload');
            }
        });
    })
</script>